﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Sustainalytics.Claims;
using Sustainalytics.DataLayer;
using Sustainalytics.Entities;
using Sustainalytics.ProductInvolvement.BL;
using Sustainalytics.ScreeningTool.BL;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Web.Http;

namespace Sustainalytics.ScreeningTool.Service.Tests
{
    [TestClass()]
    public class FilterCriteriaControllerTests
    {
        #region Mocks
        private Filter mockFilter = new Filter()
        {
            Id = new Guid("2fa3f715-e262-49d8-82dd-a06c904945d2"),
            Name = "Test filter g",
            Type = 0,
            OwnerUserId = new Guid("e9a988fa-832f-e411-83fb-d89d67630ddc"),
            AccountId = new Guid("528ea769-2d17-e411-92ce-6c3be5be9f98"),
            LastSaved = DateTime.Now,
            CreatedAt = DateTime.Now,
            IsFavorite = true,
            Status = FilterStatus.Active,
            PublishDate = null,
            UnPublishDate = null,
            PortfolioId = null,
            UniverseId = 0,
            PeerGroup = new Guid("1b29ed0c-31a5-4dfb-8431-8cb9ff0fe37c"),
            Region = null,
            Country = null,
            CompanyType = null,
            WeightMatrixId = null,
            ReferenceUniverseId = null,
            ComparativeGroup = null,
            ResearchType = null,
            TargetType = 0,
            ExportType = 0
        };

        private List<FilterCriteria> mockFilterCriteria = new List<FilterCriteria>()
        {
            new FilterCriteria()
            {
                Id = new Guid("5c686f08-e58f-4f98-9cdd-006b7d14fa20"),
                Name = "Peer Group name",
                CriteriaLevel2Id = new Guid("8b8da6c0-048e-4cbd-6510-1b2018e5ee6f"),
                CriteriaLevel3Id = new Guid("f9c443e7-ac64-f34a-c3e8-d3a8586396f4"),
                CriteriaEntity = "CorporateData",
                CriteriaEntityField = "RootPeerGroup",
                CriteriaType = CriteriaTypeEnum.CriteriaType3,
                FilterId = new Guid("2fa3f715-e262-49d8-82dd-a06c904945d2"),
                FilterGroupId = null,
                Order = 1,
                IsDataPoint = false,
                SelectedValue = "{\"SelectedItems\":[\"Banks\",\"Commercial Services\",\"Building Products\",\"Construction & Engineering\"]}",
                SelectedValueInformation = "Banks, Commercial Services, Building Products, Construction & Engineering",
                TemplateCriteriaId = new Guid("c357e4f0-a840-4df2-fa4e-1099024a7680")
            },

            new FilterCriteria()
            {
                Id = new Guid("33241d16-a5bf-4281-9318-af3441d5e4a7"),
                Name = "E.3.1.9 GMO Policy Summary",
                CriteriaLevel2Id = new Guid("200086af-bfc0-46ae-2dc2-e9dea4db2e5d"),
                CriteriaLevel3Id = new Guid("78cce16e-cef5-584b-f74c-da5d6739e70a"),
                CriteriaEntity = "RPIndicator",
                CriteriaEntityField = "SelectedAnswer.Text",
                CriteriaType = CriteriaTypeEnum.CriteriaType5,
                FilterId = new Guid("2fa3f715-e262-49d8-82dd-a06c904945d2"),
                FilterGroupId = new Guid("efa59168-4e0c-4ec4-b695-cf8acf19fbed"),
                Order = 2,
                IsDataPoint = true,
                SelectedValue = null,
                SelectedValueInformation = null,
                TemplateCriteriaId = new Guid("5dcde8c7-a672-c548-c746-8e88bbe875fc")
           },

           new FilterCriteria()
           {
               Id = new Guid("d98bb3ab-f57c-4fe3-a797-dd152430a598"),
               Name = "E.3.1.9 GMO Policy Weight",
               CriteriaLevel2Id = new Guid("200086af-bfc0-46ae-2dc2-e9dea4db2e5d"),
               CriteriaLevel3Id = new Guid("78cce16e-cef5-584b-f74c-da5d6739e70a"),
               CriteriaEntity = "RPIndicator",
               CriteriaEntityField = "Weight",
               CriteriaType = CriteriaTypeEnum.CriteriaType5,
               FilterId = new Guid("2fa3f715-e262-49d8-82dd-a06c904945d2"),
               FilterGroupId = new Guid("efa59168-4e0c-4ec4-b695-cf8acf19fbed"),
               Order = 3,
               IsDataPoint = true,
               SelectedValue = null,
               SelectedValueInformation = null,
               TemplateCriteriaId = new Guid("352aa8d5-8d50-2a45-cb1c-d127ca7dfa30")
           }
        };

        private User mockCurrentUser = new User()
        {
            Id = new Guid("e9a988fa-832f-e411-83fb-d89d67630ddc"),
            AccountId = new Guid("e9a988fa-832f-e411-83fb-d89d67630ddc"),
            Email = "testuser@sustainalytics.com"
        };
        #endregion

        #region Delete

        [TestMethod]
        public void DeleteFilterCriteria()
        {
            var filterId = new Guid("2fa3f715-e262-49d8-82dd-a06c904945d2");
            var filterCriteriaId = new Guid("5c686f08-e58f-4f98-9cdd-006b7d14fa20");

            var mockICompanyScreening =  new Mock<ICompanyScreening>();
            var mockIFilterManager = new Mock<IFilterManager>();
            var mockIFilterCriteriaManager = new Mock<IFilterCriteriaManager>();
            var mockPIManager = new Mock<IProductInvolvementBussinesLogic>();

            var mockIClaimsChecker = new Mock<IClaimsChecker>();
            mockIClaimsChecker.Setup(x => x.Validate(It.IsAny<ClaimsPrincipal>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<List<ResourceParameters>>()))
                .Returns(true);

            var mockIAccountsRepository = new Mock<IAccountsRepository>();

            var controller = new FilterCriteriaController(mockICompanyScreening.Object, mockIFilterManager.Object, mockIFilterCriteriaManager.Object, mockIClaimsChecker.Object, mockIAccountsRepository.Object, mockPIManager.Object);

            controller.Request = new HttpRequestMessage();
            controller.Request.SetConfiguration(new HttpConfiguration());

            // Act
            var response = controller.Delete(filterId, filterCriteriaId);
            Assert.IsTrue(response.StatusCode == HttpStatusCode.OK);
        }

        [TestMethod]
        public void DeleteFilterCriteriaNoClaims()
        {
            var filterId = new Guid("2fa3f715-e262-49d8-82dd-a06c904945d2");
            var filterCriteriaId = new Guid("5c686f08-e58f-4f98-9cdd-006b7d14fa20");

            var mockICompanyScreening = new Mock<ICompanyScreening>();
            var mockIFilterManager = new Mock<IFilterManager>();
            var mockIFilterCriteriaManager = new Mock<IFilterCriteriaManager>();
            var mockPIManager = new Mock<IProductInvolvementBussinesLogic>();

            var mockIClaimsChecker = new Mock<IClaimsChecker>();
            mockIClaimsChecker.Setup(x => x.Validate(It.IsAny<ClaimsPrincipal>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<List<ResourceParameters>>()))
                .Returns(false);

            var mockIAccountsRepository = new Mock<IAccountsRepository>();

            var controller = new FilterCriteriaController(mockICompanyScreening.Object, mockIFilterManager.Object, mockIFilterCriteriaManager.Object, mockIClaimsChecker.Object, mockIAccountsRepository.Object, mockPIManager.Object);

            controller.Request = new HttpRequestMessage();
            controller.Request.SetConfiguration(new HttpConfiguration());

            // Act
            var response = controller.Delete(filterId, filterCriteriaId);
            Assert.IsTrue(response.StatusCode == HttpStatusCode.Forbidden);
        }

        [TestMethod]
        public void DeleteFilterCriteriaGroup()
        {
            var filterId = new Guid("2fa3f715-e262-49d8-82dd-a06c904945d2");
            var filterCriteriaId = new Guid("5c686f08-e58f-4f98-9cdd-006b7d14fa20");
            var filterGroupId = new Guid("efa59168-4e0c-4ec4-b695-cf8acf19fbed");

            var mockICompanyScreening = new Mock<ICompanyScreening>();
            var mockIFilterManager = new Mock<IFilterManager>();
            var mockIFilterCriteriaManager = new Mock<IFilterCriteriaManager>();
            var mockPIManager = new Mock<IProductInvolvementBussinesLogic>();

            var mockIClaimsChecker = new Mock<IClaimsChecker>();
            mockIClaimsChecker.Setup(x => x.Validate(It.IsAny<ClaimsPrincipal>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<List<ResourceParameters>>()))
                .Returns(true);

            var mockIAccountsRepository = new Mock<IAccountsRepository>();

            var controller = new FilterCriteriaController(mockICompanyScreening.Object, mockIFilterManager.Object, mockIFilterCriteriaManager.Object, mockIClaimsChecker.Object, mockIAccountsRepository.Object, mockPIManager.Object);

            controller.Request = new HttpRequestMessage();
            controller.Request.SetConfiguration(new HttpConfiguration());

            // Act
            var response = controller.Patch(filterId, filterCriteriaId, filterGroupId);
            Assert.IsTrue(response.StatusCode == HttpStatusCode.OK);
        }

        [TestMethod]
        public void DeleteFilterCriteriaGroupNoFilterGroupId()
        {
            var filterId = new Guid("2fa3f715-e262-49d8-82dd-a06c904945d2");
            var filterCriteriaId = new Guid("5c686f08-e58f-4f98-9cdd-006b7d14fa20");

            var mockICompanyScreening = new Mock<ICompanyScreening>();
            var mockIFilterManager = new Mock<IFilterManager>();
            var mockIFilterCriteriaManager = new Mock<IFilterCriteriaManager>();
            var mockPIManager = new Mock<IProductInvolvementBussinesLogic>();

            var mockIClaimsChecker = new Mock<IClaimsChecker>();
            mockIClaimsChecker.Setup(x => x.Validate(It.IsAny<ClaimsPrincipal>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<List<ResourceParameters>>()))
                .Returns(true);

            var mockIAccountsRepository = new Mock<IAccountsRepository>();

            var controller = new FilterCriteriaController(mockICompanyScreening.Object, mockIFilterManager.Object, mockIFilterCriteriaManager.Object, mockIClaimsChecker.Object, mockIAccountsRepository.Object, mockPIManager.Object);

            controller.Request = new HttpRequestMessage();
            controller.Request.SetConfiguration(new HttpConfiguration());

            // Act
            var response = controller.Patch(filterId, filterCriteriaId, null);
            Assert.IsTrue(response.StatusCode == HttpStatusCode.OK);
        }

        [TestMethod]
        public void DeleteFilterCriteriaGroupNoClaims()
        {
            var filterId = new Guid("2fa3f715-e262-49d8-82dd-a06c904945d2");
            var filterCriteriaId = new Guid("5c686f08-e58f-4f98-9cdd-006b7d14fa20");
            var filterGroupId = new Guid("efa59168-4e0c-4ec4-b695-cf8acf19fbed");

            var mockICompanyScreening = new Mock<ICompanyScreening>();
            var mockIFilterManager = new Mock<IFilterManager>();
            var mockIFilterCriteriaManager = new Mock<IFilterCriteriaManager>();
            var mockPIManager = new Mock<IProductInvolvementBussinesLogic>();

            var mockIClaimsChecker = new Mock<IClaimsChecker>();
            mockIClaimsChecker.Setup(x => x.Validate(It.IsAny<ClaimsPrincipal>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<List<ResourceParameters>>()))
                .Returns(false);

            var mockIAccountsRepository = new Mock<IAccountsRepository>();

            var controller = new FilterCriteriaController(mockICompanyScreening.Object, mockIFilterManager.Object, mockIFilterCriteriaManager.Object, mockIClaimsChecker.Object, mockIAccountsRepository.Object, mockPIManager.Object);

            controller.Request = new HttpRequestMessage();
            controller.Request.SetConfiguration(new HttpConfiguration());

            // Act
            var response = controller.Patch(filterId, filterCriteriaId, filterGroupId);
            Assert.IsTrue(response.StatusCode == HttpStatusCode.Forbidden);
        }

        #endregion

        ////[TestMethod()]
        ////public void FilterCriteriaControllerGetCollectionTest()
        ////{

        ////    // get by filter id, criteriaid, type 3 , template = true/false,  filter:filter yes no 

        ////    throw new NotImplementedException();
        ////}

        ////[TestMethod()]
        ////public void FilterCriteriaControllerGetByIdTest()
        ////{
        ////    // get by filter id, criteriaid, type 1/2/3/4/5/6 , template = true/false,  filter:filter- type 3 
        ////    // 





        ////    throw new NotImplementedException();
        ////}

        //[TestMethod()]
        //public void FilterCriteriaControllerPostTest()
        //{ 
        //    // create { type: 1, minValue: minValue, maxValue: maxValue, templateid: criteriaTemplateId }
        //    // create { type: 2, score: score, templateid: criteriaTemplateId }
        //    // create { type: 3, items: selectedItems, templateid: criteriaTemplateId }
        //    // create { type: 5, score: score, templateNumber: templateNumber, templateid: criteriaTemplateId}
        //    // create { type: 6, minValue: minValue, maxValue: maxValue, templateid: criteriaTemplateId }

        //    var criteriaIdArr = new Guid []{Guid.NewGuid(), Guid.NewGuid(),Guid.NewGuid(),Guid.NewGuid(),Guid.NewGuid(),Guid.NewGuid(),Guid.NewGuid(),Guid.NewGuid()};
        //    var filterId = Guid.NewGuid();
        //    var userId = Guid.NewGuid();

        //    var templateId1 = Guid.NewGuid();
        //    var expectedId1 = Guid.NewGuid();
        //    var c1 = new FilterCriteriaDto() { CriteriaType = (CriteriaTypeEnum)1, MinValue = 10, MaxValue = 20, TemplateId = templateId1 };


        //    var templateId2 = Guid.NewGuid();
        //    var expectedId2 = Guid.NewGuid();
        //    var c2 = new FilterCriteriaDto() { CriteriaType = (CriteriaTypeEnum)2, Score = 5, TemplateId = templateId2 };

        //    var templateId3 = Guid.NewGuid();
        //    var expectedId3 = Guid.NewGuid();
        //    var c3 = new FilterCriteriaDto() { CriteriaType = (CriteriaTypeEnum)3, SelectedItems = new List<string>(), TemplateId = templateId3 };
        //    c3.SelectedItems.Add("s1");
        //    c3.SelectedItems.Add("s2");
        //    c3.SelectedItems.Add("s3");


        //    var templateId5 = Guid.NewGuid();
        //    var expectedId5 = Guid.NewGuid();
        //    var c5 = new FilterCriteriaDto() { CriteriaType = (CriteriaTypeEnum)5, Score = 25, TemplateIndicatorNumber = "E.1.1", TemplateId = templateId5 };

        //    var templateId6 = Guid.NewGuid();
        //    var expectedId6 = Guid.NewGuid();
        //    var c6 = new FilterCriteriaDto() { CriteriaType = (CriteriaTypeEnum)6, MinValue = 10, MaxValue = 100, TemplateId = templateId6 };



        //    var saved1 = (CriteriaTypeOne)null;
        //    var saved2 = (CriteriaTypeTwo)null;
        //    var saved3 = (CriteriaTypeThree)null;
        //    var saved5 = (CriteriaTypeFive)null;
        //    var saved6 = (CriteriaTypeSix)null;

        //    var expected1 = new CriteriaTypeOne() { MinValue = 10, MaxValue = 20, Id = criteriaIdArr[1] };
        //    var expected2 = new CriteriaTypeTwo() { Score = 5, Id = criteriaIdArr[2] };
        //    var expected3 = new CriteriaTypeThree() { SelectedItems = new List<string>(), Id = criteriaIdArr[3] };
        //    expected3.SelectedItems.Add("s1");
        //    expected3.SelectedItems.Add("s2");
        //    expected3.SelectedItems.Add("s3");
        //    var expected5 = new CriteriaTypeFive() { Score = 25, TemplateIndicatorNumber = "E.1.1", Id = criteriaIdArr[5] };
        //    var expected6 = new CriteriaTypeSix() { MinValue = 10, MaxValue = 100, Id = criteriaIdArr[6] };

        //    var currentUserName = System.Threading.Thread.CurrentPrincipal.Identity.Name;         
        //    var blLayer = new StubICompanyScreening()
        //    {
        //        AddCriteriaTypeOneGuidInt32Int32String = (Guid id, int  min, int max, string username) => 
        //        {
        //            if (username == currentUserName && templateId1 == id)
        //            {
        //                saved1 = new CriteriaTypeOne() { MinValue = min, MaxValue = max, Id = criteriaIdArr[1] };
        //                return saved1;
        //            }
        //            return null;
        //        } 
        //        ,
        //        AddCriteriaTypeTwoGuidNullableOfInt32String = (Guid id, int? score, string username) =>
        //        {
        //            if (username == currentUserName && templateId2 == id)
        //            {
        //                saved2 = new CriteriaTypeTwo() { Score = score, Id = criteriaIdArr[2] };
        //                return saved2;
        //            }
        //            return null;
        //        }
        //        ,
        //        AddCriteriaTypeThreeGuidStringListOfStringString = (Guid id, string collectionName, List<string> items,  string username) =>
        //        {
        //            if (username == currentUserName && templateId3 == id)
        //            {
        //                saved3 = new CriteriaTypeThree() { SelectedItems = items, CollectionName = collectionName, Id = criteriaIdArr[3] };
        //                return saved3;
        //            }
        //            return null;
        //        }
        //        ,
        //        AddCriteriaTypeFiveGuidNullableOfInt32StringString = (Guid id, int? score, string templateno, string username) => 
        //        {
        //            if (username == currentUserName && templateId5 == id)
        //            {
        //                saved5 = new CriteriaTypeFive() { Score = score, TemplateIndicatorNumber = templateno, Id = criteriaIdArr[5] };
        //                return saved5;
        //            }
        //            return null;
        //        }
        //        ,
        //        AddCriteriaTypeSixGuidInt32Int32String = (Guid id, int min, int max, string username) => 
        //        {
        //            if (username == currentUserName && templateId6 == id)
        //            {
        //                saved6 = new CriteriaTypeSix() { MinValue = min, MaxValue = max, Id = criteriaIdArr[6] };
        //                return saved6;
        //            }
        //            return null;
        //        }
        //        /*,               
        //        SaveCurrentFilterStringStringBooleanBoolean = (String userName, String filterName, Boolean shared, Boolean createNew) =>
        //        {
        //            //if (createNew)
        //            //    savedDto = new FilterDto { Name = filterName, Shared = shared };

        //            //return new RootFilterDetails() { Filter = new FilterDetails() { FilterId = expectedId } };//todo 
        //            return null;
        //        }*/
        //    };

        //    var accrep = new StubIAccountsRepository()
        //    {
        //        GetUserByUsernameString = (string username) =>
        //        {
        //            if (currentUserName == username)
        //                return new Sustainalytics.Entities.User() { Id = userId, Email = "testuser@sustainalytics.com" };
        //            return null;
        //        }
        //    };

        //    var controller = Utils.setupController(new FilterCriteriaController(blLayer, accrep, ScreeningToolEventSource.Log));
        //    var response1 = controller.Post(filterId, c1);
        //    var response2 = controller.Post(filterId, c2);
        //    var response3 = controller.Post(filterId, c3);
        //    var response5 = controller.Post(filterId, c5);
        //    var response6 = controller.Post(filterId, c6);

        //    Utils.AreEqualByPublicProperty(saved1, expected1, "  content saved incorectly ");
        //    Utils.AreEqualByPublicProperty(saved2, expected2, "  content saved incorectly ");
        //    Utils.AreEqualByPublicProperty(saved3, expected3, "  content saved incorectly ");
        //    Utils.AreEqualByPublicProperty(saved5, expected5, "  content saved incorectly ");
        //    Utils.AreEqualByPublicProperty(saved6, expected6, "  content saved incorectly ");

        //    Assert.IsTrue(response1.AreExpected(HttpStatusCode.Created, new { CriteriaId = criteriaIdArr[1] }), " unexpected response");
        //    Assert.IsTrue(response2.AreExpected(HttpStatusCode.Created, new { CriteriaId = criteriaIdArr[2] }), " unexpected response");
        //    Assert.IsTrue(response3.AreExpected(HttpStatusCode.Created, new { CriteriaId = criteriaIdArr[3] }), " unexpected response");
        //    Assert.IsTrue(response5.AreExpected(HttpStatusCode.Created, new { CriteriaId = criteriaIdArr[5] }), " unexpected response");
        //    Assert.IsTrue(response6.AreExpected(HttpStatusCode.Created, new { CriteriaId = criteriaIdArr[6] }), " unexpected response");

        //}

        //[TestMethod()]
        //public void FilterCriteriaControllerPatchTest()
        //{
        //    // test update  resourceid: criteriaId, score: score, templateNumber: templateNumber, type: 5 
        //    // update resourceid: criteriaId, minValue: minValue, maxValue: maxValue, type: 6 
        //    // update { Verb: "PATCH", resourceid: criteria.id, criteria: criteria, type: 3 }
        //    // [{ Verb: "PATCH", resourceid: criteriaId, score: score, type: 2 }]
        //    // [{ Verb: "PATCH", resourceid: criteriaId, minValue: minValue, maxValue: maxValue, type: 1 }]
        //    // [{ Verb: "DELETE", resourceid: criteriaId }]


        //     var filterId = Guid.NewGuid();
        //    var userId = Guid.NewGuid();

        //    var criteriaId1 = Guid.NewGuid();
        //    var expectedId1 = Guid.NewGuid();
        //    var c1 = new FilterCriteriaPatchOpDto() { Verb = "PATCH", CriteriaType = 1, MinValue = 10, MaxValue = 20, ResourceId = criteriaId1 };

        //    var criteriaId2 = Guid.NewGuid();
        //    var expectedId2 = Guid.NewGuid();
        //    var c2 = new FilterCriteriaPatchOpDto() { Verb = "PATCH", CriteriaType = 2, Score = 5, ResourceId = criteriaId2 };

        //    var criteriaId3 = Guid.NewGuid();
        //    var expectedId3 = Guid.NewGuid();
        //    var c3 = new FilterCriteriaPatchOpDto() { Verb = "PATCH", CriteriaType = 3, SelectedItems = new List<string>(), ResourceId = criteriaId3 };
        //    c3.SelectedItems.Add("s1");
        //    c3.SelectedItems.Add("s2");
        //    c3.SelectedItems.Add("s3");

        //    var criteriaId5 = Guid.NewGuid();
        //    var expectedId5 = Guid.NewGuid();
        //    var c5 = new FilterCriteriaPatchOpDto() { Verb = "PATCH", CriteriaType = 5, Score = 25, TemplateNumber = "E.1.1", ResourceId = criteriaId5 };

        //    var criteriaId6 = Guid.NewGuid();
        //    var expectedId6 = Guid.NewGuid();
        //    var c6 = new FilterCriteriaPatchOpDto() { Verb = "PATCH", CriteriaType = 6, MinValue = 10, MaxValue = 100, ResourceId = criteriaId6 };



        //    var saved1 = (CriteriaTypeOne)null;
        //    var saved2 = (CriteriaTypeTwo)null;
        //    var saved3 = (CriteriaTypeThree)null;
        //    var saved5 = (CriteriaTypeFive)null;
        //    var saved6 = (CriteriaTypeSix)null;

        //    var expected1 = new CriteriaTypeOne() { MinValue = 10, MaxValue = 20, Id = criteriaId1 };
        //    var expected2 = new CriteriaTypeTwo() { Score = 5, Id = criteriaId2 };
        //    var expected3 = new CriteriaTypeThree() { SelectedItems = new List<string>(), Id = criteriaId3 };
        //    expected3.SelectedItems.Add("s1");
        //    expected3.SelectedItems.Add("s2");
        //    expected3.SelectedItems.Add("s3");
        //    var expected5 = new CriteriaTypeFive() { Score = 25, TemplateIndicatorNumber = "E.1.1", Id = criteriaId5 };
        //    var expected6 = new CriteriaTypeSix() { MinValue = 10, MaxValue = 100, Id = criteriaId6 };

        //    var toDeleteId = Guid.NewGuid();
        //    var deletedId = Guid.Empty;          
        //    var deletedAllId = Guid.Empty;

        //    var currentUserName = System.Threading.Thread.CurrentPrincipal.Identity.Name;
        //    var blLayer = new StubICompanyScreening()
        //    {
        //        UpdateCriteriaTypeOneStringGuidInt32Int32 = (string username, Guid id, int min, int max) =>
        //        {
        //            if (username == currentUserName && criteriaId1 == id)
        //                saved1 = new CriteriaTypeOne() { MinValue = min, MaxValue = max, Id = id };
        //        }
        //        ,
        //        UpdateCriteriaTypeTwoStringGuidNullableOfInt32 = (string username, Guid id, int? score) =>
        //        {
        //            if (username == currentUserName && criteriaId2 == id)
        //                saved2 = new CriteriaTypeTwo() { Score = score, Id = id };
        //        }
        //        ,
        //        UpdateCriteriaTypeThreeStringGuidStringListOfString = (string username, Guid id, string collectionName, List<string> items) =>
        //        {
        //            if (username == currentUserName && criteriaId3 == id)
        //                saved3 = new CriteriaTypeThree() { SelectedItems = items, CollectionName = collectionName, Id = id };
        //        }
        //        ,
        //        UpdateCriteriaTypeFiveStringGuidNullableOfInt32String = (string username,  Guid id, int? score, string templateno) =>
        //        {
        //            if (username == currentUserName && criteriaId5 == id)
        //                saved5 = new CriteriaTypeFive() { Score = score, TemplateIndicatorNumber = templateno, Id = id };                        
        //        }
        //        ,
        //        UpdateCriteriaTypeSixGuidInt32Int32String = (Guid id, int min, int max, string username) =>
        //        {
        //            if (username == currentUserName && criteriaId6 == id)                    
        //                saved6 = new CriteriaTypeSix() { MinValue = min, MaxValue = max, Id = id };                        
        //        },
        //        DeleteCriteriaStringGuid = (string username, Guid id) =>
        //        {
        //            if (username == currentUserName)                    
        //               deletedId = id;      
        //        },
        //        DeleteAllCriteriaStringGuid = (string username, Guid id) =>
        //        {
        //            if (username == currentUserName)                    
        //               deletedAllId = id;      
        //        }
        //        /*,               
        //        SaveCurrentFilterStringStringBooleanBoolean = (String userName, String filterName, Boolean shared, Boolean createNew) =>
        //        {
        //            //if (createNew)
        //            //    savedDto = new FilterDto { Name = filterName, Shared = shared };

        //            //return new RootFilterDetails() { Filter = new FilterDetails() { FilterId = expectedId } };//todo 
        //            return null;
        //        }*/
        //    };

        //    var accrep = new StubIAccountsRepository()
        //    {
        //        GetUserByUsernameString = (string username) =>
        //        {
        //            if (currentUserName == username)
        //                return new Sustainalytics.Entities.User() { Id = userId, Email = "testuser@sustainalytics.com" };
        //            return null;
        //        }
        //    };


        //    var updateList = new List<FilterCriteriaPatchOpDto>();
        //    updateList.Add(c1);
        //    updateList.Add(c2);
        //    updateList.Add(c3);
        //    updateList.Add(c5);
        //    updateList.Add(c6);
        //    updateList.Add(new FilterCriteriaPatchOpDto() { Verb = "DELETE",  ResourceId = toDeleteId });
        //    updateList.Add(new FilterCriteriaPatchOpDto() { Verb = "DELETE", DeleteAll = true });

        //    var controller = Utils.setupController(new FilterCriteriaController(blLayer, accrep, ScreeningToolEventSource.Log));
        //    var response1 = controller.Patch(filterId, updateList);

        //    Utils.AreEqualByPublicProperty(saved1, expected1, "  content saved incorectly ");            
        //    Utils.AreEqualByPublicProperty(saved2, expected2, "  content saved incorectly ");
        //    Utils.AreEqualByPublicProperty(saved3, expected3, "  content saved incorectly ");
        //    Utils.AreEqualByPublicProperty(saved5, expected5, "  content saved incorectly ");
        //    Utils.AreEqualByPublicProperty(saved6, expected6, "  content saved incorectly ");
        //    Assert.AreEqual(toDeleteId, deletedId, " delete fails");
        //    Assert.AreEqual(deletedAllId, filterId, " delete fails");
        //    Assert.AreEqual(HttpStatusCode.OK, response1.StatusCode, " http status code incorect");            
        //}
    }
}
